package com.ll.collectiondemo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 * @author 刘龙
 * @version 1.0
 */
public class CollectionExercise {
    public static void main(String[] args) {
        Collection collection = new ArrayList();
        collection.add(new Dog("小黄", 5));
        collection.add(new Dog("大黄", 15));

        for (Object object : collection) {
            Dog dog = (Dog) object;
            System.out.println(dog.getName());
        }

        Iterator iterator = collection.iterator();
        while (iterator.hasNext()) {
            Object object = iterator.next();
            Dog dog = (Dog) object;
            System.out.println(dog.getName());
        }
    }
}

class Dog {
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
